package com.base.vistter.iframe.inverter.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.base.vistter.iframe.bean.Result;
import com.base.vistter.iframe.entity.InverterAlarmDetails;
import com.base.vistter.iframe.exception.IframeException;
import com.base.vistter.iframe.service.InverterAlarmDetailsService;
import com.base.vistter.iframe.utils.IoUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/alarm/details")
public class InverterAlarmDetailsController {
    @Resource(name = "inverterAlarmDetailsService")
    private InverterAlarmDetailsService inverterAlarmDetailsService;

    @GetMapping
    public Result<Page<InverterAlarmDetails>> get(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(value = "pageNum", defaultValue = "10") Integer pageNum, Integer status, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginTime, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime, Integer stationId) throws IframeException {
        Page<InverterAlarmDetails> page = Page.of(pageNo, pageNum);
        return Result.ok(inverterAlarmDetailsService.pageAlarmDetails(page, status, beginTime, endTime, stationId));
    }

    @GetMapping("/download")
    public void download(HttpServletResponse response, Integer status, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginTime, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) throws IframeException {
        List<InverterAlarmDetails> list = inverterAlarmDetailsService.downloadList(status, beginTime, endTime);
        IoUtils.importExcel("告警列表", "告警列表", response, InverterAlarmDetails.class, list);
    }


}
